//
//  ClaimSuccessViewController.m
//  MemberProject
//
//  Created by vincent luo on 15/7/17.
//  Copyright (c) 2015年 MAC OS X. All rights reserved.
//

#import "ClaimSuccessViewController.h"
#import "VolunteerRecordViewController.h"
#import "ClaimProgressViewController.h"

@interface ClaimSuccessViewController ()
@property (strong, nonatomic)UIImageView *imageView;
@property(strong,nonatomic)UIButton *button;
@end

@implementation ClaimSuccessViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title=@"自助申请";
    
    self.navigationItem.hidesBackButton=YES;
    
    self.view.backgroundColor=[UIColor whiteColor];
    
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 75, SCREEN_WIDTH-20, 253*(SCREEN_WIDTH-20)/300)];
    imageView.image=[UIImage imageNamed:@"ios_48"];
    imageView.userInteractionEnabled=YES;
    [self.view addSubview:imageView];
    
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(10, SCREEN_HEIGHT-49-((SCREEN_WIDTH-20)/10)-20, SCREEN_WIDTH-20, (SCREEN_WIDTH-20)/10);
    [button setBackgroundImage:[UIImage imageNamed:@"redbar"] forState:UIControlStateNormal];
    [button setTitle:@"确  定" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(chickFinshButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    
    button=[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(100*imageView.width/300, 135*imageView.height/253, 104*imageView.width/300, 30*imageView.height/253);
    [button addTarget:self action:@selector(chickSearchButton:) forControlEvents:UIControlEventTouchUpInside];
//    button.backgroundColor=[UIColor redColor];
    [imageView addSubview:button];
}

- (void)chickFinshButton:(id)sender {
    //确定
    NSArray *arr=self.navigationController.viewControllers;
    UIViewController *resultVC=nil;
    for(int i=0;i<arr.count;i++){
        UIViewController *vc=arr[i];
        if([vc isMemberOfClass:[VolunteerRecordViewController class]]){
            resultVC=vc;
            break;
        }
    }
    if(resultVC==nil){
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
    else{
        [self.navigationController popToViewController:resultVC animated:YES];
    }
    [[NSNotificationCenter defaultCenter]postNotificationName:ClaimSuccessNotification object:nil];
}

-(void)chickSearchButton:(UIButton *)sender{
    
    void(^FinishBlock)()= ^(NSDictionary *dic)
    {
        ClaimProgressViewController *progressVC = [[ClaimProgressViewController alloc]initWithNibName:@"ClaimProgressViewController" bundle:nil];
        
        ModelClaimInfo *modelClaim = [ModelClaimInfo getClaimForDic:dic];
        [progressVC setModelClaim:modelClaim];
        [self.navigationController pushViewController:progressVC animated:YES];
        
    };
    
    [SVProgressHUD showWithStatus:@"加载中" maskType:SVProgressHUDMaskTypeBlack];
    [[BuaatVolunteerServerSDK sharedInstance]requestInsuranceSearchClaimResultWithVolunteerCode:[UserInfoManager sharedManager].modelMser.volunteerCode recordId:[UserInfoManager sharedManager].userClaimInput.recordId Success:^(NSHTTPURLResponse *response, id responseObject) {
        [SVProgressHUD dismiss];
        id result = responseObject[@"result"];
        if ([result isKindOfClass:[NSArray class]]) {
            NSArray *arr = result;
            if (arr.count>0)
            {
                FinishBlock([arr lastObject]);
            }
            
            
        }
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"网络错误" maskType:SVProgressHUDMaskTypeBlack];
    }];
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    ((BaseNavigationController *)self.navigationController).isHideInteractivePopGestureRecognizer=YES;
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    ((BaseNavigationController *)self.navigationController).isHideInteractivePopGestureRecognizer=NO;
}
@end
